﻿import socket
import sys
import time


msg_port = int(sys.argv[1])  # 通信端口

# 创建 UDP 套接字
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

server_address = ('localhost', msg_port)
sock.bind(server_address)

while True:
    data, address = sock.recvfrom(4096)
    print(f"Received {data.decode()} from {address}")
    time.sleep(1)
    # 处理接收到的数据